import {createStore, applyMiddleware} from 'redux';
// 导入reducer
import {defReducer} from './reducers/index'
// 导入 saga ，最终需要 run 执行 saga
import {defSaga} from './sagas/index'
// 导入 createSagaMiddleware
import createSagaMiddleware from 'redux-saga'
//调用一下 createSagaMiddleware 这个函数， 来构建 sagaMiddleware
const sagaMiddleware = createSagaMiddleware()

// 构建store
// createStore(reducer, initState, 中间件), 通过 applyMiddleware 来关联 saga 和 store
export default createStore(defReducer, {}, applyMiddleware(sagaMiddleware))

// 利用 Middleware run一下
sagaMiddleware.run(defSaga)
